#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<errno.h>
#include<signal.h>
#include<sys/time.h>
#include<fcntl.h>
#include<unistd.h> 
#include<pthread.h>

void* myfunc(void* p){
	int *i = (int*) malloc(sizeof(int));
	*i = (long long) p;
	printf("pthread:this is %d\n", *i);
	pthread_exit((void*)i);
}

int main(int argc, char* args[])
{
	pthread_t tid[5];
	pthread_t *tidp = tid;
	int ret;
	for(int i = 0; i < 5; i ++, tidp ++){
		printf("before create, tid = %lu\n", *tidp);
		ret = pthread_create(tidp, NULL, myfunc, (void*)i);
		if(ret){
			perror("pthread_creat error");
			exit(1);
		}
		
		printf("after create tid = %lu\n", *tidp);
		int* retval;
		pthread_join(*tidp, (void**) &retval);
		printf("join %d\n", *retval);
	}
	return 0;
}
